package com;

import java.util.ArrayList;
import java.util.List;

import cn.hutool.core.bean.BeanUtil;
import lombok.Builder;
import lombok.Data;

public class SplitHalfList {
	public static void main(String[] args) {
		List<GlassDTO> list = new ArrayList<>();
		for(int i=0;i<10;i++) {
			GlassDTO one = GlassDTO.builder()
					.index(i+1)
					.code((i+1) + "_code")
					.name((i+1) + "_name")
					.build();
			list.add(one);
		}
		System.out.println(list.size());
		System.out.println(list);
		
		int halfLength = (int) Math.ceil(list.size() * 1.0 / 2);
		System.out.println(halfLength);
		List<GlassDTO> halfList = new ArrayList<>();
		for(int i = 0; i < halfLength; i++) {
			int index = i * 2;
			GlassDTO one = BeanUtil.copyProperties(list.get(index), GlassDTO.class);
			if(index + 1 < list.size()) {
				one.setCode2(list.get(index + 1).getCode());
			} else {
				one.setCode2("X");
			}
			halfList.add(one);
		}
		System.out.println(halfList.size());
		System.out.println(halfList);
	}
	
}

@Data
@Builder
class GlassDTO {
	private Integer index;
	private String code;
	private String name;
	private String code2;
}
